<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id=main></div>

  <script>
    //协议域名端口，有一项不一样就是跨域
    fetch('http://localhost:2021/d', {
      method: 'POST',
      body: JSON.stringify({a:123}),
      headers: {
        'content-type': 'text/json'
      }
    })
    .then(res => {
      return res.text()
    })
    .then(d => {
      console.log(d);
    })
    .catch(err => {
      console.error(err)
    })

  </script>

</body>
</html>